package com.example.sxt_practise.GOF23.flyweight;

import java.util.HashMap;
import java.util.Map;

/**
 * 享元工厂类: 创建并管理享元工厂类
 * @author gaofeng
 * @date 2022年05月24日 20:11
 */
public class ChessFlyWeightFactory {

    private final static Map<String, ChessFlyWeight> map = new HashMap<>() ;

    public static ChessFlyWeight getChessFlyWeight(String color) {
        if (map.containsKey(color)) {
            return map.get(color) ;
        } else {
            ChessFlyWeight chessFlyWeight = new ConcreteCoordinate("白色") ;
            map.put("白色", chessFlyWeight) ;
            return chessFlyWeight ;
        }
    }
}
